home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / IPSORT.ICN < prev    next >
Text File  |  1992-09-28  |  2KB  |  69 lines

  1. ############################################################################
  2. #
  3. #    File:     ipsort.icn
  4. #
  5. #    Subject:  Program to sort Icon procedures
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     June 10, 1988
  10. #
  11. ###########################################################################
  12. #  
  13. #     This program reads an Icon program and writes an equivalent
  14. #  program with the procedures sorted alphabetically. Global, link,
  15. #  and record declarations come first in the order they appear in
  16. #  the original program.  The main procedure comes next followed by
  17. #  the remaining procedures in alphabetical order.
  18. #  
  19. #     Comments and white space between declarations are attached to
  20. #  the next following declaration.
  21. #  
  22. #  Limitations: This program only recognizes declarations that start
  23. #  at the beginning of a line.
  24. #  
  25. #     Comments and interline white space between declarations may
  26. #  not come out as intended.
  27. #  
  28. ############################################################################
  29.  
  30. procedure main()
  31.    local line, x, i, proctable, proclist, comments, procname
  32.  
  33.    comments := []            # list of comment lines
  34.    proctable := table()            # table of procedure declarations
  35.  
  36.    while line := read() do {
  37.      line ? {
  38.         if ="procedure" &        #  procedure declaration
  39.            tab(many('\t ')) &
  40.            procname := tab(upto('(')) | stop("*** bad syntax: ",line)
  41.         then {                # if main, force sorting order
  42.            if procname == "main" then procname := "\0main"
  43.            proctable[procname] := x := []
  44.            while put(x,get(comments))    #  save it
  45.            put(x,line)
  46.            while line := read() do {
  47.               put(x,line)
  48.               if line == "end" then break
  49.               }
  50.            }
  51.                     #  other declarations
  52.          else if =("global" | "record" | "link")
  53.          then {
  54.             while write(get(comments))
  55.             write(line)
  56.             }
  57.          else put(comments,line)
  58.          }
  59.       }
  60.  
  61.    while write(get(comments))
  62.  
  63.    proclist := sort(proctable,3)        #  sort procedures
  64.  
  65.    while get(proclist) do
  66.       every write(!get(proclist))
  67.  
  68. end
  69.